package com.fanyue.modules.wzb.service.impl;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.fanyue.core.request.R;
import com.fanyue.modules.wzb.mapper.ClothingInfoMapper;
import com.fanyue.modules.wzb.service.CountService;
import com.fanyue.modules.wzb.vo.CountClothingByCategoryVO;
import com.fanyue.modules.wzb.vo.CountClothingBySpecVO;
import com.fanyue.modules.wzb.vo.CountLendByAppUserVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;


/**
 * 系统用户
 */
@Service
@RequiredArgsConstructor
public class CountServiceImpl implements CountService {

    final private ClothingInfoMapper clothingInfoMapper;

    @Override
    public R lendCountByAppUser(JSONObject requestParams) {
        Integer category = requestParams.getInt("category");
        String keyWord = requestParams.getStr("keyWord");
        Long[] deptIds = requestParams.get("departmentIds", Long[].class);
        List<Long> departmentIds = new ArrayList<>();
        if (ArrayUtil.isNotEmpty(deptIds)) {
            departmentIds = new ArrayList<>(Arrays.asList(deptIds));
        }
        Map<String,Object> selectMap = new HashMap<>();
        if (category != null) {
            selectMap.put("category", category);
        }
        if (StrUtil.isNotEmpty(keyWord)) {
            selectMap.put("keyWord", keyWord);
        }
        if (departmentIds.size() > 0) {
            selectMap.put("department", "true");
        } else {
            selectMap.put("department", "false");
        }
        List<CountLendByAppUserVO> list = clothingInfoMapper.lendByAppUserList(selectMap, departmentIds);
        return R.ok(list);
    }

    @Override
    public R clothingBySpec(JSONObject requestParams) {
        Integer category = requestParams.getInt("category");
        Integer season = requestParams.getInt("season");
        Long specId = requestParams.getLong("specId");
        Map<String,Object> selectMap = new HashMap<>();
        if (category != null) {
            selectMap.put("category", category);
        }
        if (season != null) {
            selectMap.put("season", season);
        }
        if (specId != null) {
            selectMap.put("specId", specId);
        }
        List<CountClothingBySpecVO> list = clothingInfoMapper.clothingBySpec(selectMap);
        return R.ok(list);
    }

    @Override
    public R clothingByCategory(JSONObject requestParams) {
        List<CountClothingByCategoryVO> list = clothingInfoMapper.clothingByCategory();
        return R.ok(list);
    }
}